# -*- coding: utf-8 -*-
# @Time : 2024/6/6 1:00 PM 
# @Author : Wayne
# @Email : 1
# @File : jd_caigou.py
# @Project : young_python_demo
# @DESCRIPTION :

KD_data = [
        {
            "FID": 104650,
            "FBillNo": "HZP003989-1",
            "FRemainStockINQty": 77,
            "FMaterialId_fnumber": "CE01862757ERGMAG",
            "FBusinessType": "WW",
            "FSRCBillNo": "SUB00001532",
            "FQty": 180,
            "FTaxPrice": 483,
            "FPOOrderEntry_FEntryID": 111304,
            "FPurchaseOrgId_fnumber": "101",
            "FSupplierId_fnumber": "AG"
        },
        {
            "FID": 104650,
            "FBillNo": "HZP003989-1",
            "FRemainStockINQty": 20,
            "FMaterialId_fnumber": "CE01862757ERGMAG",
            "FBusinessType": "WW",
            "FSRCBillNo": "SUB00001532",
            "FQty": 20,
            "FTaxPrice": 431,
            "FPOOrderEntry_FEntryID": 111305,
            "FPurchaseOrgId_fnumber": "101",
            "FSupplierId_fnumber": "AG"
        },
        {
            "FID": 104650,
            "FBillNo": "HZP003989-1",
            "FRemainStockINQty": 20,
            "FMaterialId_fnumber": "CE01142757ERGMAG",
            "FBusinessType": "WW",
            "FSRCBillNo": "SUB00001532",
            "FQty": 20,
            "FTaxPrice": 341,
            "FPOOrderEntry_FEntryID": 111308,
            "FPurchaseOrgId_fnumber": "101",
            "FSupplierId_fnumber": "AG"
        },
        {
            "FID": 104650,
            "FBillNo": "HZP003989-1",
            "FRemainStockINQty": 140,
            "FMaterialId_fnumber": "CE01152757ERSRAG",
            "FBusinessType": "WW",
            "FSRCBillNo": "SUB00001532",
            "FQty": 410,
            "FTaxPrice": 403,
            "FPOOrderEntry_FEntryID": 111309,
            "FPurchaseOrgId_fnumber": "101",
            "FSupplierId_fnumber": "AG"
        },
        {
            "FID": 104650,
            "FBillNo": "HZP003989-1",
            "FRemainStockINQty": 60,
            "FMaterialId_fnumber": "CE01152757ERSRAG",
            "FBusinessType": "WW",
            "FSRCBillNo": "SUB00001532",
            "FQty": 60,
            "FTaxPrice": 351,
            "FPOOrderEntry_FEntryID": 111310,
            "FPurchaseOrgId_fnumber": "101",
            "FSupplierId_fnumber": "AG"
        },
        {
            "FID": 104650,
            "FBillNo": "HZP003989-1",
            "FRemainStockINQty": 35,
            "FMaterialId_fnumber": "CE01152757ERGMAG",
            "FBusinessType": "WW",
            "FSRCBillNo": "SUB00001532",
            "FQty": 35,
            "FTaxPrice": 351,
            "FPOOrderEntry_FEntryID": 111311,
            "FPurchaseOrgId_fnumber": "101",
            "FSupplierId_fnumber": "AG"
        },
        {
            "FID": 104650,
            "FBillNo": "HZP003989-1",
            "FRemainStockINQty": 178,
            "FMaterialId_fnumber": "CE01862757ERSRAG",
            "FBusinessType": "WW",
            "FSRCBillNo": "SUB00001532",
            "FQty": 190,
            "FTaxPrice": 483,
            "FPOOrderEntry_FEntryID": 111312,
            "FPurchaseOrgId_fnumber": "101",
            "FSupplierId_fnumber": "AG"
        },
        {
            "FID": 104650,
            "FBillNo": "HZP003989-1",
            "FRemainStockINQty": 180,
            "FMaterialId_fnumber": "CE01152757ERGMAG",
            "FBusinessType": "WW",
            "FSRCBillNo": "SUB00001532",
            "FQty": 180,
            "FTaxPrice": 403,
            "FPOOrderEntry_FEntryID": 111313,
            "FPurchaseOrgId_fnumber": "101",
            "FSupplierId_fnumber": "AG"
        }
    ]


# 获取金蝶上游单据行ID
def get_FEntryID(jky_code, jky_qty, kd_list):
    for item in kd_list:
        # 如果金蝶的物料代码=吉客云的货品代码
        if item["FMaterialId_fnumber"] == jky_code:
            print(item["FMaterialId_fnumber"])
            # 金蝶数量
            FRemainStockINQty = float(str(item.get("FRemainStockINQty")))
            # 且金蝶的数量大于吉客云的数量
            if FRemainStockINQty >= float(str(jky_qty)):
                print("33333333")
                # 金蝶商品数量减去吉客云商品数量
                item["FRemainStockINQty"] = FRemainStockINQty - float(str(jky_qty))
                # 返回金蝶id
                return item["FPOOrderEntry_FEntryID"]
            # else:
            #     continue
    return None

good_no ="CE01152757ERSRAG"
print(get_FEntryID(good_no, 200, KD_data))

# FInStockEntry_Link_dic.update({'FInStockEntry_Link_FSId': get_FEntryID(i.get('goodsNo'), i.get('quantity'), KD_data)})